//package com.funny.stock.config.security;
//
//import org.springframework.security.access.AccessDecisionManager;
//import org.springframework.security.access.AccessDeniedException;
//import org.springframework.security.access.ConfigAttribute;
//import org.springframework.security.authentication.InsufficientAuthenticationException;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.stereotype.Service;
//import org.springframework.util.CollectionUtils;
//
//import java.util.Collection;
//
//@Service
//public class MyAccessDecisionManager implements AccessDecisionManager {
//
//
//    @Override
//    public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes) throws AccessDeniedException, InsufficientAuthenticationException {
//        if(CollectionUtils.isEmpty(configAttributes)) {
//            return;
//        }
//
//        Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
//
//        ConfigAttribute configAttribute = configAttributes.stream().filter(item -> {
//            String attribute = item.getAttribute();
//            GrantedAuthority authority = authorities.stream().filter(key -> key.getAuthority().equals(attribute))
//                    .findFirst().orElse(null);
//            return authority != null;
//        }).findFirst().orElse(null);
//
//        if(configAttribute != null) return;
//
//        throw new AccessDeniedException("没有权限操作，请先申请权限");
//
//    }
//
//    @Override
//    public boolean supports(ConfigAttribute attribute) {
//        return true;
//    }
//
//    @Override
//    public boolean supports(Class<?> clazz) {
//        return true;
//    }
//
//
//
//}